package org.cloud.test;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.SimpleMailMessage;

import java.util.Properties;

public class MailSenderExample {
    public static void main(String[] args) {
        // 配置JavaMailSenderImpl
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtpout.secureserver.net");
        mailSender.setPort(465);
        mailSender.setUsername("support@qvpn.live");
        mailSender.setPassword("zs6LskuSMCa2Wbne");
        mailSender.setProtocol("smtp");

        // 额外的JavaMail属性
        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.timeout", "5000");
        props.put("mail.smtp.ssl.enable", "true");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

        // 创建邮件
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("support@qvpn.live");
        message.setTo("93334958@qq.com");  // <-- 替换成实际收件人
        message.setSubject("测试邮件（JavaMailSender）");
        message.setText("这是通过JavaMailSenderImpl发送的一封测试邮件。");

        // 发送邮件
        mailSender.send(message);

        System.out.println("邮件发送成功！");
    }
}
